package com.ruoyi.lxzx.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lxzx.domain.UserReal;
import com.ruoyi.lxzx.service.IUserRealService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * realController
 * 
 * @author ruoyi
 * @date 2024-11-30
 */
@RestController
@RequestMapping("/system/real")
public class UserRealController extends BaseController
{
    @Autowired
    private IUserRealService userRealService;

    /**
     * 查询real列表
     */
    @PreAuthorize("@ss.hasPermi('system:real:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserReal userReal)
    {
        startPage();
        List<UserReal> list = userRealService.selectUserRealList(userReal);
        return getDataTable(list);
    }

    /**
     * 导出real列表
     */
    @PreAuthorize("@ss.hasPermi('system:real:export')")
    @Log(title = "real", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserReal userReal)
    {
        List<UserReal> list = userRealService.selectUserRealList(userReal);
        ExcelUtil<UserReal> util = new ExcelUtil<UserReal>(UserReal.class);
        util.exportExcel(response, list, "real数据");
    }

    /**
     * 获取real详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userRealService.selectUserRealById(id));
    }
    /**
     * 获取real详细信息
     */
    @GetMapping(value = "/byUserId")
    public AjaxResult byUserId(@RequestParam Long userId)
    {
        return success(userRealService.selectUserRealByUserId(userId));
    }

    /**
     * 新增real
     */
    @PreAuthorize("@ss.hasPermi('system:real:add')")
    @Log(title = "real", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserReal userReal)
    {
        return toAjax(userRealService.insertUserReal(userReal));
    }

    /**
     * 修改real
     */
    @PreAuthorize("@ss.hasPermi('system:real:edit')")
    @Log(title = "real", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserReal userReal)
    {
        return toAjax(userRealService.updateUserReal(userReal));
    }

    /**
     * 删除real
     */
    @PreAuthorize("@ss.hasPermi('system:real:remove')")
    @Log(title = "real", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userRealService.deleteUserRealByIds(ids));
    }
}
